<template>
  <div>
    <el-row :gutter="10" justify="end" type="flex">
      <el-col :span="5">
        <el-select v-model="year" @change="changeYear">
          <el-option v-for="item in years" :key="item" :label="item" :value="item"></el-option>
        </el-select>
      </el-col>
      <el-col :span="5">
        <el-select v-model="month" @change="changeMonth">
          <el-option v-for="item in 30" :key="item" :label="item" :value="item"></el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-calendar v-model="value">
      <template slot="dateCell" slot-scope="{date, data}">
        <p :class="data.isSelected ? 'is-selected' : ''">
          {{ data.day.split('-').slice(2).join('-') }} {{ data.isSelected ? '✔️' : ''}}
          <span
            v-if="isWeek(date)"
            class="rest"
          >休</span>
        </p>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      year: "",
      month: "",
      years: []
    };
  },
  mounted() {
    this.initCalendar();
  },
  methods: {
    initCalendar(data = null) {
      if (!data) {
        this.value = new Date();
      } else {
        this.value = new Date(data);
      }
      this.month = this.value.getMonth() + 1;
      this.year = this.value.getFullYear();
      this.years = Array.from(
        Array(11),
        (value, index) => this.year + index - 5
      );
    },
    changeYear(val) {
      let data = this.value.setFullYear(val);
      this.initCalendar(data);
    },
    changeMonth(val) {
      let data = this.value.setMonth(val - 1);
      this.initCalendar(data);
    },
    // 是否是休息日
    isWeek(value) {
      return value.getDay() === 6 || value.getDay() === 0;
    }
  }
};
</script>

<style scoped>
/deep/ .el-calendar-day {
  height: 40px;
  text-align: center;
}
/deep/ .el-calendar-table__row td,
/deep/ .el-calendar-table tr td:first-child,
/deep/ .el-calendar-table__row td.prev {
  border: none;
}
.date-content {
  height: 50px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
/deep/ .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
/deep/ .el-calendar__header {
  display: none;
}
.rest {
  display: inline-block;
  font-size: 12px;
  line-height: 18px;
  height: 18px;
  width: 18px;
  color: white;
  background-color: red;
  border-radius: 20px;
}
</style>